
#ifndef SX_OPENGL_PICKING_CONTROLLER_H
#define SX_OPENGL_PICKING_CONTROLLER_H

#include <sxPickingController.h>
#include <sxCamera.h>

/* Sx library types.*/
using Sx::Graphics::Picking::PickingController;
using Sx::Graphics::Objects::Camera;

namespace Sx {
namespace OpenGL {
namespace Graphics {
namespace Picking {

class OpenGL_PickingController : public PickingController<Camera> {
public:
	OpenGL_PickingController();
	virtual ~OpenGL_PickingController();

	bool construct();

	/* 
	 * This function should be called before this picking controller is to be
	 * used. This will update the state of the view projection and model view.
	 */
	bool update();

	bool project(const Camera* const camera, const Eigen::Vector3f& worldPoint, Eigen::Vector2i& viewPoint);
	bool unproject(const Camera* const camera, int x, int y, Eigen::Vector3f& origin, Eigen::Vector3f& direction);

	bool createPickRay(const Camera* const camera, int x, int y, Eigen::Vector3f& start, Eigen::Vector3f& end);
 
protected:
	static const unsigned int MATRIX_SIZE = 16;
	static const unsigned int VIEWPORT_DIMENSIONS = 4;

	/* Used to store the OpenGL matrices relevant to this controller. */
	double projMatrix[MATRIX_SIZE];
	double modelMatrix[MATRIX_SIZE];
	int viewport[VIEWPORT_DIMENSIONS];
};

}

}

}

}

#endif
